package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.Setmeal;
import com.itheima.vo.CheckGroupVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author ：yuanjian
 * @date ：Created in 2020/11/11 14:52
 * @description：
 */
public interface SetMealMapper extends BaseMapper<Setmeal> {
    @Insert("insert into `t_setmeal_checkgroup` values(#{setmealId},#{checkgroupId})")
    void addSetmealAndCheckGroupIds( @Param("setmealId") Long setmealId,@Param("checkgroupId") Long checkgroupId);

    @Select("select checkgroup_id from `t_setmeal_checkgroup`  where setmeal_id=#{setmealId}")
    List<Long> findCheckGroupBySetmealId(Long setmealId);

    @Delete("delete from `t_setmeal_checkgroup` where setmeal_id=#{setmealId}")
    void deleteCheckGroupBySetmealId(Long groupId);

    @Select("select  tcg.* \n" +
            "from t_setmeal_checkgroup tscg left join t_check_group tcg on tscg.checkgroup_id = tcg.id \n" +
            "WHERE tcg.is_delete=0 and tscg.setmeal_id =#{sid}")
    List<CheckGroupVo> findCheckGroupsBySetmealId(@Param("sid") Long sid);
}
